package Sort.面试.工银澳门JAVA面试题;

import java.math.BigDecimal;

public class Fruit {

    /**
     * 加法：add函数
     * 减法：subtract()函数
     * 乘法：multiply()函数
     * 除法：divide()函数
     * 绝对值：abs()函数
     */
    public final static BigDecimal APPLE_PRICE = BigDecimal.valueOf(8);
    public final static BigDecimal STRAWBERRY_PRICE = BigDecimal.valueOf(13);
    public final static BigDecimal MANGO_PRICE = BigDecimal.valueOf(20);

    /**
     *
     * @param appleWeight 苹果重量
     * @param strawberryWeight 草莓重量
     * @param mangoWeight 芒果重量
     * @param disCount 是否打折
     * @return
     */
    public static BigDecimal shopping(Integer appleWeight, Integer strawberryWeight, Integer mangoWeight, boolean disCount){
        // 苹果支付价格
        BigDecimal applePay = APPLE_PRICE.multiply(BigDecimal.valueOf(appleWeight));
        //芒果支付价格
        BigDecimal mangoPay = MANGO_PRICE.multiply(BigDecimal.valueOf(mangoWeight));;

        BigDecimal strawberryPay;
        // 草莓是否有折扣
        if(disCount){
            strawberryPay = STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(strawberryWeight)).multiply(BigDecimal.valueOf(0.8));
        }else{
            strawberryPay = STRAWBERRY_PRICE.multiply(BigDecimal.valueOf(strawberryWeight));
        }

        return hundredMinusTen(applePay.add(strawberryPay).add(mangoPay));
    }


    /**
     * 每满100减去10
     * @param money
     * @return
     */
    public static BigDecimal hundredMinusTen(BigDecimal money){
        double coin = Double.valueOf(String.valueOf(money));

        Integer num = (int) coin / 100;

        return money.subtract(BigDecimal.valueOf(num * 10));
    }

    //测试
    public static void main(String[] args) {
        BigDecimal shopping = shopping(10, 10, 10, false);
        System.out.println(shopping);
    }
}
